//
//  CompanyStoryTableViewCell.m
//  XRSquare
//
//  Created by 穆相臣 on 2018/11/16.
//  Copyright © 2018 UaenaMo. All rights reserved.
//

#import "CompanyStoryTableViewCell.h"

@interface CompanyStoryTableViewCell ()
{
    UILabel * titleLabel;
    UILabel * contentLabel;
    UIButton * shareButton;
    
    UIView * line;
}
@end

@implementation CompanyStoryTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, ScreenWidth, 20)];
        titleLabel.font = [UIFont boldSystemFontOfSize:15];
        titleLabel.text = @"品牌故事";
        titleLabel.textColor = [UIColor colorFromHexCode:@"a3a3a3"];
        [self addSubview:titleLabel];
        
        UIButton * shareButton = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth - 60, 10, 50, 20)];
        shareButton.titleLabel.font = [UIFont systemFontOfSize:12];
        shareButton.backgroundColor = [UIColor orangeColor];
        [shareButton setTitle:@"分享" forState:UIControlStateNormal];
        shareButton.layer.cornerRadius = 10;
        [shareButton addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:shareButton];
        
        contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 40, ScreenWidth - 20, 30)];
        contentLabel.numberOfLines = 0;
        contentLabel.font = [UIFont systemFontOfSize:15];
        [self addSubview:contentLabel];
        
        line = [[UIView alloc]initWithFrame:CGRectMake(0, 50, ScreenWidth, 10)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [self addSubview:line];
    }
    return self;
}

+(CGFloat)heightWithData:(NSString *)data
{
    if (data && ![data isKindOfClass:[NSNull class]])
    {
        UILabel * lable = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, ScreenWidth - 20, 30)];
        lable.font = [UIFont systemFontOfSize:15];
        lable.text = data;
        lable.numberOfLines = 0;
        [lable sizeToFit];
        return lable.frame.size.height + 40 + 10;
    }
    else
    {
        return 0;
    }
}

-(void)shareAction
{
    [self.delegate shareCompany];
}

-(void)loadData:(NSString *)data
{
    if (data && ![data isKindOfClass:[NSNull class]])
    {
        contentLabel.frame = CGRectMake(10, 40, ScreenWidth - 20, 30);
        contentLabel.text = data;
        [contentLabel sizeToFit];
        
        line.frame = CGRectMake(0, 40 + contentLabel.frame.size.height + 5, ScreenWidth, 10);
        for (UIView * view in self.subviews)
        {
            view.hidden = NO;
        }
    }
    else
    {
        for (UIView * view in self.subviews) {
            view.hidden = YES;
        }
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
